Repository navigation
fix: limit decompressed webhook payloads to 10 MiB - #246
Merged
Merged
Conversation
gunzip_payload runs before the signature check, so an unsigned gzip bomb could exhaust memory. Decompression now stops at MAX_WEBHOOK_PAYLOAD_BYTES (default 10 MiB) and raises InvalidWebhookError. Corrupt deflate data now raises InvalidWebhookError instead of zlib.error.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Submit a pull request
CLA
Description of the pull request
Problem
gunzip_payloadinflated a gzip body with no size limit before the signature check, so an unsigned request of a few hundred KB could expand to hundreds of MB and exhaust memory on a webhook endpoint.Solution
Decompression now stops at 10 MiB and raises
InvalidWebhookError("gzip decompression failed: payload exceeds 10485760 bytes"). The same helper backsverify_and_parse_webhook,parse_sqsandparse_sns. Raise the cap if your events are larger:Uncompressed bodies are not limited, and multi-member gzip still inflates as before. Corrupt deflate data now raises
InvalidWebhookErrorinstead of leakingzlib.error. This matches the default and error message of the other server SDKs.How to verify
pytest stream_chat/tests/test_webhook_compression.py(passes locally on Python 3.8 and 3.12).verify_and_parse_webhookandparse_sqs, and honour a custom limit.Note
Medium Risk
Changes webhook ingestion before HMAC verification and rejects oversized gzip, which could break unusually large legitimate events unless the cap is raised.
Overview
Gzip webhook decompression is now bounded at 10 MiB via a new
MAX_WEBHOOK_PAYLOAD_BYTESsetting onstream_chat.webhook, becausegunzip_payloadruns before signature verification and could previously be abused with gzip bombs.Decompression switches from
gzip.decompressto a cappedGzipFile.read(limit + 1)flow. Oversized output raisesInvalidWebhookErrorwith apayload exceeds … bytesmessage; corrupt deflate data is mapped to the same webhook error (includingzlib.error). Uncompressed bodies and multi-member gzip behavior are unchanged, and the limit is tunable by assigningwebhook.MAX_WEBHOOK_PAYLOAD_BYTES.Tests cover the 10 MiB boundary, gzip-bomb rejection through
verify_and_parse_webhookandparse_sqs, corrupt streams, multi-member inflation, and a monkeypatched custom cap.Reviewed by Cursor Bugbot for commit 6322de6. Bugbot is set up for automated code reviews on this repo. Configure here.